home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / packet / p_aa4re / bb212src / bbedit.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1991-12-14  |  13.9 KB  |  413 lines

  1. (*===========================================================================*)
  2. (* Edit a file                                                               *)
  3. (*                                                                           *)
  4. (*   Copyright (c) 1985, 87 by Borland International, Inc.                   *)
  5. (*   Copyright 1988, 1989, 1991 by H. Roy Engehausen.  All rights reserved.  *)
  6. (*                                                                           *)
  7. (*   This code cannot be used in other programs except in conjunction        *)
  8. (*   with a licensed copy of the Turbo Editor Toolbox                        *)
  9. (*                                                                           *)
  10. (*===========================================================================*)
  11.  
  12. {$UNDEF DEBUG_PATH}
  13. {$UNDEF DEBUG_OVER}
  14. {$UNDEF DEBUG_BP}
  15.  
  16. {$O+}
  17.  
  18. UNIT BBEDIT;
  19.  
  20. INTERFACE
  21.  
  22.   USES
  23.     bbdummy;
  24.  
  25.   PROCEDURE edit_file_main(cmd_string : STRING);
  26.   PROCEDURE oper_et(cmd_in : STRING);
  27.   PROCEDURE oper_emptr(msg_ptr : msg_index_ptr);
  28.  
  29. IMPLEMENTATION
  30.  
  31.   USES
  32.     DOS,
  33.     CRT,
  34.     bined,
  35.     bbdump,
  36.     bbedits,
  37.     bbmdata,
  38.     bbmess,
  39.     bbmf,
  40.     bbsdata,
  41.     bbsema2,
  42.     bbstack,
  43.     bbstr,
  44.     bbtask,
  45.     bbwin;
  46.  
  47. {$I BBEDITSO.PAS}
  48.  
  49. PROCEDURE edit_file_main(cmd_string : STRING);
  50.  
  51.   VAR
  52.     b                 : BOOLEAN;
  53.     i                 : BYTE;
  54.     mem_size          : LONGINT;
  55.  
  56.   (*=========================================================================*)
  57.   (* Edit file cleanup                                                       *)
  58.   (*=========================================================================*)
  59.  
  60.   PROCEDURE edit_file_leave;
  61.     VAR
  62.       junkroy : BYTE;
  63.     BEGIN;
  64.  
  65.       releasebinaryeditorheap(eddata);
  66.  
  67.       window_select(window_reset);
  68.  
  69.       COLOR(opt_block.status_color);
  70.  
  71.       GOTOXY(1, window_location[window_full_screen].window_wl);
  72.  
  73.       CLREOL;
  74.  
  75.       window_select(window_operator);
  76.  
  77.       CLRSCR;
  78.  
  79.       i := window_cursor_update(1);
  80.  
  81.       window_refresh(window_operator);
  82.  
  83.       edit_window_busy     := FALSE;
  84.  
  85.       status_window_change := TRUE;
  86.  
  87.     END;
  88.  
  89.   (*=========================================================================*)
  90.   (* Edit main line starts here                                              *)
  91.   (*=========================================================================*)
  92.  
  93.   BEGIN;
  94.  
  95.     {$IFDEF DEBUG_PATH}
  96.       WRITELN('Edit main line start');
  97.     {$ENDIF}
  98.  
  99.     (*-----------------------------------------------------------------------*)
  100.     (* Check for valid syntax                                                *)
  101.     (*-----------------------------------------------------------------------*)
  102.  
  103.     i := WORDS(cmd_string);
  104.  
  105.     IF i <> 2 THEN
  106.       BEGIN;
  107.         IF i > 2 THEN
  108.           send_message(message_err_wrd)
  109.         ELSE
  110.           send_message(message_not_en);
  111.         active_tcb^.error_sw := TRUE;
  112.         EXIT;
  113.       END;
  114.  
  115.     fname := subword(@cmd_string, 2, 1);
  116.  
  117.     (*-----------------------------------------------------------------------*)
  118.     (* Compute memory size                                                   *)
  119.     (*-----------------------------------------------------------------------*)
  120.  
  121.     mem_size := MAXAVAIL - opt_block.editor_free;;
  122.     IF mem_size < 0 THEN
  123.       BEGIN;
  124.         window_write('ED::', ' Insufficent memory available');
  125.         active_tcb^.error_sw := TRUE;
  126.         EXIT;
  127.       END;
  128.  
  129.     IF mem_size > maxfilesize THEN
  130.       mem_size := maxfilesize;
  131.  
  132.     (*-----------------------------------------------------------------------*)
  133.     (* Initialize window info                                                *)
  134.     (*-----------------------------------------------------------------------*)
  135.  
  136.     edit_window_busy := TRUE;
  137.  
  138.     {$IFDEF DEBUG_PATH}
  139.       WRITELN('Window set');
  140.     {$ENDIF}
  141.  
  142.     window_select(window_reset);
  143.  
  144.     windx  := get_window_x(window_operator);
  145.     windx1 := HI(windx);
  146.     windx2 := LO(windx);
  147.  
  148.     windy  := get_window_y(window_operator);
  149.     windy1 := HI(windy);
  150.     windy2 := LO(windy);
  151.  
  152.     WINDOW(windx1, windy1, windx2, windy2);
  153.  
  154.     CLRSCR;
  155.  
  156.     (*-----------------------------------------------------------------------*)
  157.     (* Initialize editor                                                     *)
  158.     (*-----------------------------------------------------------------------*)
  159.  
  160.     {$IFDEF DEBUG_PATH}
  161.       WRITELN('Init');
  162.     {$ENDIF}
  163.  
  164.     exitcode := initbinaryeditor(
  165.       eddata,        (*Editor control block, initialized by InitBinaryEditor*)
  166.       mem_size,      (*Size of data area to reserve for binary editor text buffer, $FFE0 max*)
  167.       windx1 + 1,    (*Coordinates of editor window, upper left 1..80*)
  168.       windy1 + 1,    (*Coordinates of editor window, upper left 1..25*)
  169.       windx2 - 1,    (*Coordinates of editor window, lower right*)
  170.       windy2 - 1,    (*Coordinates of editor window, lower right*)
  171.       opt_block.opt_direct_snow,  (*True to wait for retrace on color cards*)
  172.       edoptinsert+edoptindent,    (*Initial editor toggles*)
  173.       '',                         (*Default extension for file names*)
  174.       myexitcommands,             (*Commands to exit editor*)
  175.       ADDR(usereventcheck));      (*Address of user event handler*)
  176.  
  177.     (*-----------------------------------------------------------------------*)
  178.     (* If editor didn't initialize ok then leave                             *)
  179.     (*-----------------------------------------------------------------------*)
  180.  
  181.     {$IFDEF DEBUG_PATH}
  182.       WRITELN('Check');
  183.     {$ENDIF}
  184.  
  185.     b := checkinitbinary(exitcode);
  186.     IF b THEN
  187.       BEGIN;
  188.         edit_file_leave;
  189.         EXIT;
  190.       END;
  191.  
  192.     (*-----------------------------------------------------------------------*)
  193.     (* Obtain the interrupt lock                                             *)
  194.     (*-----------------------------------------------------------------------*)
  195.  
  196.     get_semaphore(semaphore_interrupts, sem_exclusive, FALSE);
  197.  
  198.     (*-----------------------------------------------------------------------*)
  199.     (* Read the file and make sure it worked                                 *)
  200.     (*-----------------------------------------------------------------------*)
  201.  
  202.     exitcode := readfilebinaryeditor(eddata, fname);
  203.     b := checkreadfile(exitcode, filenamebinaryeditor(eddata));
  204.  
  205.     (*-----------------------------------------------------------------------*)
  206.     (* Release the interrupt lock                                            *)
  207.     (*-----------------------------------------------------------------------*)
  208.  
  209.     free_semaphore(semaphore_interrupts);
  210.  
  211.     (*-----------------------------------------------------------------------*)
  212.     (* If errors so far then exit                                            *)
  213.     (*-----------------------------------------------------------------------*)
  214.  
  215.     IF b THEN
  216.       BEGIN;
  217.         edit_file_leave;
  218.         EXIT;
  219.       END;
  220.  
  221.     (*-----------------------------------------------------------------------*)
  222.     (* Ready editor                                                          *)
  223.     (*-----------------------------------------------------------------------*)
  224.  
  225.     resetbinaryeditor(eddata);
  226.  
  227.     {$IFDEF DEBUG_BP}
  228.       WRITELN('BP3');
  229.       DELAY(2000);
  230.     {$ENDIF}
  231.  
  232.     (*-----------------------------------------------------------------------*)
  233.     (* Signal size not updated                                               *)
  234.     (*-----------------------------------------------------------------------*)
  235.  
  236.     edit_size := -1;
  237.  
  238.     (*-----------------------------------------------------------------------*)
  239.     (* Start status line                                                     *)
  240.     (*-----------------------------------------------------------------------*)
  241.  
  242.     initstatusline;
  243.  
  244.     (*-----------------------------------------------------------------------*)
  245.     (* Loop while editing                                                    *)
  246.     (*-----------------------------------------------------------------------*)
  247.  
  248.     REPEAT
  249.  
  250.       (*---------------------------------------------------------------------*)
  251.       (* Draw the editor window                                              *)
  252.       (*---------------------------------------------------------------------*)
  253.  
  254.       initwindow(eddata);
  255.  
  256.       (*---------------------------------------------------------------------*)
  257.       (* Execute the editor                                                  *)
  258.       (*---------------------------------------------------------------------*)
  259.  
  260.       executeeditor;
  261.  
  262.       {$IFDEF DEBUG_OVER}
  263.         WRITELN('X');
  264.         DELAY(2000);
  265.         dump_string('Ready to close');
  266.         dump_overlay;
  267.         dump_trace;
  268.       {$ENDIF}
  269.  
  270.       (*---------------------------------------------------------------------*)
  271.       (* Call exit handler                                                   *)
  272.       (*---------------------------------------------------------------------*)
  273.  
  274.       b := exitbinaryeditor(eddata, exitcomcode);
  275.  
  276.     UNTIL b;
  277.  
  278.     (*-----------------------------------------------------------------------*)
  279.     (* Clean up                                                              *)
  280.     (*-----------------------------------------------------------------------*)
  281.  
  282.     edit_file_leave;
  283.  
  284.     (*-----------------------------------------------------------------------*)
  285.     (* Tell we are done                                                      *)
  286.     (*-----------------------------------------------------------------------*)
  287.  
  288.     IF edit_operation = 0 THEN
  289.       send_message(message_op_complete);
  290.  
  291.   END;
  292.  
  293. (*===========================================================================*)
  294. (* Operator edit message text                                                *)
  295. (*===========================================================================*)
  296.  
  297. PROCEDURE oper_et(cmd_in : STRING);
  298.  
  299.   VAR
  300.     code           : INTEGER;
  301.     e_msg_no       : LONGINT;
  302.     i              : WORD;
  303.     msg_ptr        : msg_index_ptr;
  304.  
  305.   BEGIN;
  306.  
  307.     (*-----------------------------------------------------------------------*)
  308.     (* Check for valid syntax                                                *)
  309.     (*-----------------------------------------------------------------------*)
  310.  
  311.     i := WORDS(cmd_in);
  312.  
  313.     IF i <> 2 THEN
  314.       BEGIN;
  315.         IF i > 2 THEN
  316.           send_message(message_err_wrd)
  317.         ELSE
  318.           send_message(message_not_en);
  319.         active_tcb^.error_sw := TRUE;
  320.         EXIT;
  321.       END;
  322.  
  323.     (*-----------------------------------------------------------------------*)
  324.     (* Convert message number to something reasonable                        *)
  325.     (*-----------------------------------------------------------------------*)
  326.  
  327.     VAL(subword(@cmd_in, 2, 1), e_msg_no, code);
  328.  
  329.     IF (code <> 0) OR (e_msg_no < 1) OR (e_msg_no > 65535) THEN
  330.       BEGIN;
  331.         send_message(message_err_ivm);
  332.         active_tcb^.error_sw := TRUE;
  333.         EXIT;
  334.       END;
  335.  
  336.     (*-----------------------------------------------------------------------*)
  337.     (* Find the message number                                               *)
  338.     (*-----------------------------------------------------------------------*)
  339.  
  340.     msg_ptr := find_msg(e_msg_no);
  341.  
  342.     IF msg_ptr = NIL THEN
  343.       BEGIN;
  344.         send_message(message_rmc_nf);
  345.         active_tcb^.error_sw := TRUE;
  346.         EXIT;
  347.       END;
  348.  
  349.     (*-----------------------------------------------------------------------*)
  350.     (* Build the edit command                                                *)
  351.     (*-----------------------------------------------------------------------*)
  352.  
  353.     STR(e_msg_no, cmd_in);
  354.     cmd_in := 'EF ' + opt_block.msg_file_dir + 'BB' + cmd_in + '.MSG';
  355.  
  356.     (*-----------------------------------------------------------------------*)
  357.     (* Call edit                                                             *)
  358.     (*-----------------------------------------------------------------------*)
  359.  
  360.     edit_file_main(cmd_in);
  361.  
  362.     (*-----------------------------------------------------------------------*)
  363.     (* If size updated, change header                                        *)
  364.     (*-----------------------------------------------------------------------*)
  365.  
  366.     IF edit_size >= 0 THEN
  367.       BEGIN;
  368.         msg_ptr^.msg_i_mb.msg_size := edit_size + 1;
  369.         update_msg(msg_ptr);
  370.       END;
  371.  
  372.   END;
  373.  
  374. (*===========================================================================*)
  375. (* Operator edit message text based on a pointer                             *)
  376. (*===========================================================================*)
  377.  
  378. PROCEDURE oper_emptr(msg_ptr : msg_index_ptr);
  379.  
  380.   VAR
  381.     s : STRING;
  382.  
  383.   BEGIN;
  384.  
  385.     (*-----------------------------------------------------------------------*)
  386.     (* Build the edit command                                                *)
  387.     (*-----------------------------------------------------------------------*)
  388.  
  389.     STR(msg_ptr^.msg_i_mb.msg_number, s);
  390.     s := 'EF ' + opt_block.msg_file_dir + 'BB' + s + '.MSG';
  391.  
  392.     (*-----------------------------------------------------------------------*)
  393.     (* Call edit                                                             *)
  394.     (*-----------------------------------------------------------------------*)
  395.  
  396.     edit_parm := msg_ptr;
  397.  
  398.     edit_file_main(s);
  399.  
  400.     (*-----------------------------------------------------------------------*)
  401.     (* If size updated, change header                                        *)
  402.     (*-----------------------------------------------------------------------*)
  403.  
  404.     IF edit_size >= 0 THEN
  405.       BEGIN;
  406.         msg_ptr^.msg_i_mb.msg_size := edit_size + 1;
  407.         update_msg(msg_ptr);
  408.       END;
  409.  
  410.   END;
  411.  
  412. END.
  413.